<?php 
class infoAction extends AdminMaster{
	private $tbl = null;
	public function execute($request){
		sfContext::getInstance()->getConfiguration()->loadHelpers('I18N');
		$this->tbl = new SysAccounts();
		$this->data['navigation']	= __('module_sys_accounts',null,'menu').' › '. __('module_sys_accounts_action_accounts',null,'menu');
		
		
		$this->formData				= $request->getParameter('UserPassword');	//get form data from add new || edit page
		$us = $this->getUser()->getAttribute('admin.accounts');
		$this->data['id'] = $us['id'];
		$this->editRecord();
		$this->setVar('data', $this->data);
	}	
	
	
	/*
	 * EDIT
	 */
	private function editRecord(){
		$this->data['navigation'].=' › '. __('nav_edit',null,'table_list');
		$this->data['button_action'] = __('button_edit',null,'table_list');
		
		$form = new UserPasswordForm();
		if($this->data['is_post']){
			
			$us = $this->getUser()->getAttribute('admin.accounts');
			$sys_account = SysAccounts::login(array('login_user' => $us['login_user'], 'login_password' => $this->formData['current_password']));
			if(count($sys_account)){
				if(SysAccountIpLockeds::checkIPLockeds()){
					$this->formData['id'] = $this->data['id'];
					if($this->tbl->updatePassword($this->formData)){
						$this->data['result']	= __('edit_success', null, 'sys_account');
					}else{
						$this->data['result']	= sprintf(__('edit_error', null, 'table_list'), sfConfig::get('app_email_admin')) ;
					}
				}else{
					$this->data['result'] = 'current password is invalid ! 1';
				}
			
			}else{
				$this->data['result'] = 'current password is invalid ! 2';
			}
		}
		$data = $this->tbl->getById($this->data['id']);
		if(count($data)<0){
			$this->redirect($this->data['redirect']);
		}else{
			$this->formData = array(
						'name'		=> $data['name'],
						'email'		=> $data['email'],
						'login_user'=> $data['login_user'],
						'group_id'	=> $data['group_id'],
						'is_enabled'=> $data['is_enabled'],
						'_csrf_token'=> $form->getCSRFToken()
					);
			$form->bind($this->formData);
		}
		
		$this->setVar('form', $form);
		
	}
	
}